@extends('user._layouts.default')

@section('css')
    {{HTML::style('user/css/base.css')}}
@stop

@section('user-main')
<div style="font-size: 25px;">{{{$title or ''}}}<a href="{{URL::to('user/message')}}" class="am-btn am-fr am-btn-xs am-btn-primary">全部管理</a></div>
<hr/>

<div data-am-widget="tabs" class="am-tabs am-tabs-default">
  <ul class="am-tabs-nav am-cf">
    <li class="am-active">
      <a href="[data-tab-panel-0]">用户留言</a>
    </li>

    <li class="">
      <a href="[data-tab-panel-1]">系统消息</a>
    </li>
  </ul>
  <div class="am-tabs-bd">
    <div data-tab-panel-0 class="am-tab-panel am-active">
        <div class="am-margin-top-sm">
          <div class="am-u-sm-6 am-fl am-margin-bottom my-padding-left-0">
{{--             <form class="am-form-inline" role="form" action="{{URL::to('user/message')}}">
              <div class="am-form-group">
                <input type="text" class="am-form-field am-input-sm" name="keywords" placeholder="留言内容或用户">
              </div>
              <button type="submit" class="am-btn am-btn-default am-input-sm">搜索</button>
            </form> --}}
          </div>
          <div  class="am-u-sm-6 am-margin-bottom my-padding-right-0">
            <button type="submit" class="am-btn am-btn-default am-fr am-input-sm am-margin-left-xs" id="clear_user_message">清空所有留言</button>
            <button type="submit" class="am-btn am-btn-default am-fr am-input-sm"  data-am-modal="{target: '#doc-modal-1', closeViaDimmer: 0}">发送留言</button>
          </div>
        </div>
        <hr data-am-widget="divider" style="" class="am-divider am-divider-default"
/>
        <div>
        <ul class="am-comments-list am-comments-list-flip">
        @foreach($user_messages as $message)
          <li class="am-comment">
            <a href="#link-to-user-home">
              <img src="http://static.oschina.net/uploads/user/0/1_50.jpg?t=1389148177000" alt="" class="am-comment-avatar" width="48" height="48"/>
            </a>

            <div class="am-comment-main" style="margin-right:0px;">
              <header class="am-comment-hd">
                <div class="am-comment-meta">
                  <p class="am-inline am-fl" style="margin:0px;"><a href="#link-to-user" class="am-comment-author">{{$message->from_user_id}}{{$message->to_user_id}}</a>
                  留言于 <time datetime="2013-07-27T04:54:29-07:00" title="2013年7月27日 下午7:54 格林尼治标准时间+0800">{{$message->created_at}}</time>
                  </p>
                  <p class="am-inline am-fr" style="margin:0px;"><a href="">回复</a> | <a href="{{URL::to('user/message/lists/'.$message->to_user_id)}}">查看(共29条)</a> | <a href="">删除</a></p>
                </div>
              </header>

              <div class="am-comment-bd">
                {{$message->message_content}}
              </div>
            </div>
          </li>
        @endForeach
        </ul>
        </div>
        <div>
          {{$user_messages->links('public.pagination')}}
        </div>
    </div>
    <div data-tab-panel-1 class="am-tab-panel ">
                <div class="am-margin-top-sm">
                  <div class="am-u-sm-6 am-fl am-margin-bottom my-padding-left-0">
 {{--                    <form class="am-form-inline" role="form">
                      <div class="am-form-group">
                        <input type="text" class="am-form-field am-input-sm" placeholder="留言内容或用户">
                      </div>
                      <button type="submit" class="am-btn am-btn-default am-input-sm">搜索</button>
                    </form> --}}
                  </div>
                  <div  class="am-u-sm-6 am-margin-bottom my-padding-right-0">
                    <button type="submit" id="clear_system_message" class="am-btn am-btn-default am-fr am-input-sm am-margin-left-xs">清空系统消息</button>
                  </div>
                </div>
                <hr data-am-widget="divider" style="" class="am-divider am-divider-default"
        />
                <div>
                <ul class="am-comments-list am-comments-list-flip">
                @foreach($system_messages as $message)
                  <li class="am-comment">
                    <a href="#link-to-user-home">
                      <img src="http://static.oschina.net/uploads/user/0/1_50.jpg?t=1389148177000" alt="" class="am-comment-avatar" width="48" height="48"/>
                    </a>

                    <div class="am-comment-main" style="margin-right:0px;">
                      <header class="am-comment-hd">
                        <div class="am-comment-meta">
                          <p class="am-inline am-fl" style="margin:0px;"><a href="#link-to-user" class="am-comment-author">{{$message->from_user_id}}{{$message->to_user_id}}</a>
                          留言于 <time datetime="2013-07-27T04:54:29-07:00" title="2013年7月27日 下午7:54 格林尼治标准时间+0800">{{$message->created_at}}</time>
                          </p>
                          <p class="am-inline am-fr" style="margin:0px;"> <a href="">删除</a></p>
                        </div>
                      </header>

                      <div class="am-comment-bd">
                        {{$message->message_content}}
                      </div>
                    </div>
                  </li>
                @endForeach
                </ul>
                </div>
                <div>
                  {{$system_messages->links('public.pagination')}}
                </div>
    </div>
</div>
</div>


<!-- 发留言弹出窗 -->
<div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-1">
  <div class="am-modal-dialog">
    <div class ="am-modal-hd" style="background: #fcfcfcf;">发送留言
      <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
    </div>
    <div class="am-modal-bd">
      <div class="am-alert am-hide" id="alert-message" data-am-alert>
        <button type="button" class="am-close">&times;</button>
        <p id="alert-message-content"></p>
      </div>
      <form class="am-form am-form-horizontal am-margin-top-lg" method="post" action="{{URL::to('user/message/dosend')}}">

        <div class="am-form-group">
            <label for="doc-ipt-3" class="am-u-sm-3 am-form-label">用户</label>
            <div class="am-u-sm-9">
              <input type="text" name="to_user_id" id="to_user_id">
            </div>
          </div>
        <div class="am-form-group">
            <label for="doc-ipt-3" class="am-u-sm-3 am-form-label">消息内容</label>
            <div class="am-u-sm-9">
              <textarea name="message_content" id="message_content"></textarea>
            </div>
          </div>
        <div class="am-form-group">
            <div class="am-u-sm-9 am-u-sm-offset-3">
              <button type="button" class="am-btn am-btn-default am-fl" id="send_message">发送</button>
            </div>
          </div>
      </form>
    </div>
  </div>
</div>
<!-- 发留言弹出窗END -->
@stop
<!--[if (gte IE 9)|!(IE)]><!-->
@section('js')
<script type="text/javascript" src="{{\URL::asset('user/js/base.js')}}"></script>
<script type="text/javascript">
//发送留言窗口
$('#send_message').click(function(){
  var to_user_id = $('#to_user_id').val();
  var message_content = $('#message_content').val();
  var to_send = $.post("{{URL::to('user/message/dosend')}}",{to_user_id:to_user_id,message_content:message_content},function(data){
      var send_type = 'am-alert-'+data.type;
      $('#alert-message').removeClass('am-hide').addClass('am-block').removeClass('am-alert-danger').removeClass('am-alert-success').addClass(send_type);
      $('#alert-message-content').text(data.content);
      setTimeout(function(){
        $('#doc-modal-1').modal('close');
      },1000);
  });
});

//开始清空用户留言
$('#clear_user_message').on('click',function(){
  clear_message(1);
});

//开始清空系统消息
$('#clear_system_message').on('click',function(){
  clear_message(2);
});

//清空留言消息
function clear_message(type){
  $.post('{{URL::to("user/message/clear")}}',{type:type},function(data){
      alert(data.content);
      window.location.href = window.location.href;
  })
}

</script>
@stop
